/*
 * @Description: 路由文件配置
 * @Author: seadon
 * @LastEditors: seadon
 * @Date: 2021-07-07 10:46:58
 * @LastEditTime: 2022-07-19 10:55:33
 */
import { createRouter, createWebHashHistory } from 'vue-router'
import { customRouterChanged } from '@byteluck-fe/global-shared'
import routes from './routers'
import store from '@/store'
import { client } from '@/utils'

const router = createRouter({
	history: createWebHashHistory(process.env.VUE_APP_BASE_PATH + 'desktop'),
	routes,
})

router.beforeEach((to, from, next) => {
	if (location.href.indexOf('turnOnTheStarter') == -1) {
		if (!client.isPc()) {
			window.location.href = 'mobile.html'
		}
		if (sessionStorage.getItem('IAppLauncher')) {
			sessionStorage.removeItem('IAppLauncher')
		}
		if (sessionStorage.getItem('multipleTabs')) {
			sessionStorage.removeItem('multipleTabs')
		}
		if (sessionStorage.getItem('appLauncherList')) {
			sessionStorage.removeItem('appLauncherList')
		}
	}
	//qiyu 2021-10-29 --task=1004337 --user=戚雨 【私有化环境】增加空文件用来存放私有化本地信息 https://www.tapd.cn/67265839/s/1148189
	customRouterChanged(to, from)

	if (
		(!store.state.tenant.tenant_auth.baiteda_security_account ||
			store.state.tenant.env_type != 'prd') &&
		to.name === 'Welcome'
	) {
		next({ name: 'home' })
	}

	!store.state.centerUser.user_base_info &&
	store.state.tenant.tenant_auth.baiteda_security_account &&
	store.state.tenant.env_type === 'prd' &&
	from.name === 'Welcome'
		? next({ name: 'Welcome' })
		: next()
})

export { routes }
export default router
